/**************************************************************************************************

	NSurvey - The web survey and form engine
	Copyright (c) 2004, Thomas Zumbrunn. (http://www.nsurvey.org)

	Dotnetnuke PA module 
	Copyright (c) 2004, Oliver Hine (oliver.hine@gmail.com)

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


************************************************************************************************/
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Votations.NSurvey.DataAccess;
using Votations.NSurvey.Data;
using Votations.NSurvey.BusinessRules;
using Votations.NSurvey.WebAdmin.UserControls;
using Votations.NSurvey.Emailing;
using Votations.NSurvey.Web;
using Votations.NSurvey.Web.Security;
using DotNetNuke;

namespace Votations.NSurvey.WebAdmin
{
	public class nSurveyAdmin: PageBase
	{

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
			//base.Actions.Add(GetNextActionID(), "Active Survey Selector", "","","", get_EditURL("","" , "Settings"),false, SecurityAccessLevel.Edit, true,false);
			CreateLinks();

		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			SurveyOption.OptionChanged += new EventHandler(SurveyOption_OptionChanged);

		}
		#endregion

		protected SurveyOptionControl SurveyOption;
		protected HeaderControl Header;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				if (!Page.IsPostBack)
				{
					// Init the user control with the current survey id
					SurveyOption.SurveyId = SurveyId; 
					Header.SurveyId = SurveyId; 
				}
			}
			catch( Exception exc) 
			{
				DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this,exc);
			}
		}

		private void SetupSecurity()
		{
			CheckRight(NSurveyRights.AccessSurveySettings, true);
		}

		/// <summary>
		///	Triggered by the survey option user control
		///	in case anything was changed we will need to
		///	rebind to display the updates to the user 
		/// </summary>
		void SurveyOption_OptionChanged(object sender, EventArgs e)
		{
			// Retrieve the new control survey ID
			SurveyId = ((SurveyOptionControl)sender).SurveyId;
	
			// In case the control changed the current survey
			Header.SurveyId = SurveyId; 
		}
	}
}